package com.ruoyi.busi.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.common.core.page.PagePlus;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.stereotype.Service;
import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.busi.domain.bo.BusiCompanyEfBo;
import com.ruoyi.busi.domain.vo.BusiCompanyEfVo;
import com.ruoyi.busi.domain.BusiCompanyEf;
import com.ruoyi.busi.mapper.BusiCompanyEfMapper;
import com.ruoyi.busi.service.IBusiCompanyEfService;

import java.util.List;
import java.util.Map;
import java.util.Collection;

/**
 * 碳排放Service业务层处理
 *
 * @author ruoyi
 * @date 2024-12-02
 */
@Service
public class BusiCompanyEfServiceImpl extends ServicePlusImpl<BusiCompanyEfMapper, BusiCompanyEf, BusiCompanyEfVo> implements IBusiCompanyEfService {

    @Override
    public BusiCompanyEfVo queryById(Long id){
        return getVoById(id);
    }

    @Override
    public TableDataInfo<BusiCompanyEfVo> queryPageList(BusiCompanyEfBo bo) {
        PagePlus<BusiCompanyEf, BusiCompanyEfVo> result = pageVo(PageUtils.buildPagePlus(), buildQueryWrapper(bo));
        return PageUtils.buildDataInfo(result);
    }

    @Override
    public List<BusiCompanyEfVo> queryList(BusiCompanyEfBo bo) {
        return listVo(buildQueryWrapper(bo));
    }

    private LambdaQueryWrapper<BusiCompanyEf> buildQueryWrapper(BusiCompanyEfBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<BusiCompanyEf> lqw = Wrappers.lambdaQuery();
        lqw.eq(StringUtils.isNotBlank(bo.getSb1()), BusiCompanyEf::getSb1, bo.getSb1());
        lqw.eq(StringUtils.isNotBlank(bo.getSb2()), BusiCompanyEf::getSb2, bo.getSb2());
        lqw.eq(StringUtils.isNotBlank(bo.getSb3()), BusiCompanyEf::getSb3, bo.getSb3());
        lqw.eq(StringUtils.isNotBlank(bo.getSb4()), BusiCompanyEf::getSb4, bo.getSb4());
        lqw.eq(StringUtils.isNotBlank(bo.getSb5()), BusiCompanyEf::getSb5, bo.getSb5());
        lqw.eq(StringUtils.isNotBlank(bo.getSb6()), BusiCompanyEf::getSb6, bo.getSb6());
        lqw.eq(StringUtils.isNotBlank(bo.getSb7()), BusiCompanyEf::getSb7, bo.getSb7());
        lqw.eq(StringUtils.isNotBlank(bo.getSb8()), BusiCompanyEf::getSb8, bo.getSb8());
        lqw.eq(StringUtils.isNotBlank(bo.getSb9()), BusiCompanyEf::getSb9, bo.getSb9());
        lqw.eq(StringUtils.isNotBlank(bo.getSb10()), BusiCompanyEf::getSb10, bo.getSb10());
        lqw.eq(StringUtils.isNotBlank(bo.getSb11()), BusiCompanyEf::getSb11, bo.getSb11());
        lqw.eq(StringUtils.isNotBlank(bo.getSb12()), BusiCompanyEf::getSb12, bo.getSb12());
        lqw.eq(StringUtils.isNotBlank(bo.getSb13()), BusiCompanyEf::getSb13, bo.getSb13());
        lqw.eq(StringUtils.isNotBlank(bo.getSb14()), BusiCompanyEf::getSb14, bo.getSb14());
        lqw.eq(StringUtils.isNotBlank(bo.getSb15()), BusiCompanyEf::getSb15, bo.getSb15());
        lqw.eq(StringUtils.isNotBlank(bo.getSb16()), BusiCompanyEf::getSb16, bo.getSb16());
        lqw.eq(StringUtils.isNotBlank(bo.getSb17()), BusiCompanyEf::getSb17, bo.getSb17());
        lqw.eq(StringUtils.isNotBlank(bo.getSb18()), BusiCompanyEf::getSb18, bo.getSb18());
        lqw.eq(StringUtils.isNotBlank(bo.getSb19()), BusiCompanyEf::getSb19, bo.getSb19());
        lqw.eq(StringUtils.isNotBlank(bo.getSb20()), BusiCompanyEf::getSb20, bo.getSb20());
        return lqw;
    }

    @Override
    public Boolean insertByBo(BusiCompanyEfBo bo) {
        BusiCompanyEf add = BeanUtil.toBean(bo, BusiCompanyEf.class);
        validEntityBeforeSave(add);
        boolean flag = save(add);
        if (flag) {
            bo.setId(add.getId());
        }
        return flag;
    }

    @Override
    public Boolean updateByBo(BusiCompanyEfBo bo) {
        BusiCompanyEf update = BeanUtil.toBean(bo, BusiCompanyEf.class);
        validEntityBeforeSave(update);
        return updateById(update);
    }

    /**
     * 保存前的数据校验
     *
     * @param entity 实体类数据
     */
    private void validEntityBeforeSave(BusiCompanyEf entity){
        //TODO 做一些数据校验,如唯一约束
    }

    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if(isValid){
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return removeByIds(ids);
    }
}
